#include "thread.h"
#include <stdio.h>
#include <assert.h>

static void * threadfunc(void * arg)
{
	char *name = arg;
	int i;
	for(i=0; i<5; i++)
	{
		printf("%s : %d\n", name, i);
		thread_yield();
	}

	//thread_exit(arg);
}

int main()
{
  thread_t thread1, thread2, thread3, thread4;
  void *retval1, *retval2, *retval3, *retval4;
  int err;

  init();

  err = thread_create(&thread1, threadfunc, "t1");
  thread1->priority = 1; 
  assert(!err);
  err = thread_create(&thread2, threadfunc, "t2");
  assert(!err);
  err = thread_create(&thread3, threadfunc, "t3");
  assert(!err);
  err = thread_create(&thread4, threadfunc, "t4");
  thread4->priority = 40; 
  assert(!err);

  
  err = thread_join(thread1, &retval1);
  assert(!err);
  err = thread_join(thread2, &retval2);
  assert(!err);
  err = thread_join(thread3, &retval3);
  assert(!err);
  err = thread_join(thread4, &retval4);
  assert(!err);

  return 0;
}
